package logic

import (
	"context"
	"message/models"

	"message/internal/svc"
	"message/pb/message"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateMessageLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateMessageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateMessageLogic {
	return &CreateMessageLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// CreateMessage 发送消息
func (l *CreateMessageLogic) CreateMessage(in *message.MessageInfo) (*message.MessageInfo, error) {
	err := l.svcCtx.MessageAggregationModel.CreateMessage(l.ctx, &models.Message{
		SenderId:     in.SenderId,
		ReceiverType: in.ReceiverType,
		ReceiverId:   in.ReceiverId,
		ContentType:  in.ContentType,
		Content:      in.Content,
		FileName:     in.FileName,
		FileSize:     in.FileSize,
		Status:       in.Status,
	}, in.ReceiverIds)
	if err != nil {
		return nil, err
	}
	return &message.MessageInfo{}, nil
}
